From f149beb4749898050188a6006363adef4e652917 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 21 Jun 2020 04:11:24 +0200 Subject: [PATCH] gtk-demo: Add a permutation to compute colors from the position This way, the colors are furthest apart at the start and fill up the remaining spots towards the end. --- demos/gtk-demo/listview_colors.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/demos/gtk-demo/listview_colors.c b/demos/gtk-demo/listview_colors.c index 9ec5dc3328..a50a180d96 100644 --- a/demos/gtk-demo/listview_colors.c +++ b/demos/gtk-demo/listview_colors.c @@ -330,6 +330,32 @@ gtk_color_list_get_n_items (GListModel *list) return N_COLORS; } +static guint +position_to_color (guint position) +{ + static guint map[] = { + 0xFF0000, 0x00FF00, 0x0000FF, + 0x7F0000, 0x007F00, 0x00007F, + 0x3F0000, 0x003F00, 0x00003F, + 0x1F0000, 0x001F00, 0x00001F, + 0x0F0000, 0x000F00, 0x00000F, + 0x070000, 0x000700, 0x000007, + 0x030000, 0x000300, 0x000003, + 0x010000, 0x000100, 0x000001 + }; + guint result, i; + + result = 0; + + for (i = 0; i < G_N_ELEMENTS (map); i++) + { + if (position & (1 << i)) + result ^= map[i]; + } + + return result; +} + static gpointer gtk_color_list_get_item (GListModel *list, guint position) @@ -339,6 +365,8 @@ gtk_color_list_get_item (GListModel *list, if (position >= N_COLORS) return NULL; + position = position_to_color (position); + if (self->colors[position] == NULL) { guint red, green, blue; -- 2.30.2